package com.fund.client.controller;

import com.fund.api.entity.TradeOrder;
import com.fund.client.pojo.entity.BankCard;
import com.fund.client.service.BankCardService;
import com.fund.common.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bankCard")
public class BankCardController {

    @Autowired
    BankCardService bankCardService;

    /**
     * 删除银行卡
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteBankCard(@PathVariable Long id) {
        return Result.success(bankCardService.removeById(id));
    }

    /**
     * 新增银行卡
     * @param bankCard
     * @return
     */
    @PostMapping
    public Result<Boolean> addBankCard(@RequestBody BankCard bankCard) {
        return bankCardService.addBankCard(bankCard);
    }

    /**
     * 根据id查询银行卡
     * @param id
     * @return
     */
    @GetMapping
    public Result<BankCard> getBankCardById(Long id) {
        return Result.success(bankCardService.getById(id));
    }

    /**
     * 根据客户查询银行卡
     * @return
     */
    @GetMapping("/list")
    public Result<List<BankCard>> getBankCardsByClientId(@RequestParam Long clientId) {
        return bankCardService.getByClientId(clientId);
    }

    @PutMapping("/orders")
    public Result<Boolean> updateBalanceByOrders(@RequestBody List<TradeOrder> tradeOrderList) {
        return bankCardService.updateBalanceByOrders(tradeOrderList);
    }

    @PostMapping("/recharge")
    public Result<Boolean> recharge(){
        return Result.fail("该接口等待完善");
    }

}
